<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    // 1.面试题一
    var n = 100
    function foo() { n = 200 }
    foo()
    console.log(n) // 200
  </script>
  <script>
    // 2.面试题二
    var n = 100
    function foo() {
      console.log(n) // undefined
      var n = 200
      console.log(n) // 200
    }
    foo() // undefined 200
  </script>
  <script>
    // 3.面试题三
    var n = 100
    function foo1() {
      console.log(n) // 100
    }
    function foo2() {
      var n = 200
      console.log(n) // 200
      foo1()
    }
    foo2() // 200 100
  </script>
  <script>
    // 4.面试四
    var a = 100
    function foo() {
      console.log(a) // undefined
      return
      var a = 200
    }
    foo() // undefined
  </script>
  <script>
    // 5.在开发中可能会出现这样错误的写法
    message = "Hello World"
    function foo() {
      message = "Hello world foo"
    }
  </script>
  <script>
    // 5.面试题五
    function foo() {
      var a = b = 100
    }
    foo()
    console.log(a) // 100
    console.log(b) // 100

  </script>
</body>

</html>